﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BIZ;
using DAL;

namespace SinhNhat.admin
{
    public partial class AdminArticle : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            ArticleBIZ articleBIZ = new ArticleBIZ();
            
            CollectionPager1.DataSource = articleBIZ.getAll();
            CollectionPager1.BindToControl = grArticle;
            grArticle.DataSource = CollectionPager1.DataSourcePaged;
            grArticle.DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            grArticle.RowCommand += new GridViewCommandEventHandler(grArticle_RowCommand);
        }

        void grArticle_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Guid articleID = WebUtils.ToGuid(e.CommandName);
            ArticleBIZ articleBIZ = new ArticleBIZ();

            if (e.CommandArgument.Equals("True"))
            {
                articleBIZ.ChangeStatus(articleID, false);                
            }
            else if (e.CommandArgument.Equals("False"))
            {
                articleBIZ.ChangeStatus(articleID, true);
            }
            
            LoadData();
        }
    }
}